package com.wpf.flux2client;

import com.wpf.interfaces.ProxyCreator;
import com.wpf.api.IPersonApi;
import com.wpf.proxy.JDKProxyCreator;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Flux2clientApplication {

    public static void main(String[] args) {
        SpringApplication.run(Flux2clientApplication.class, args);
    }

    @Bean
    ProxyCreator jdkProxyCreator(){
        return new JDKProxyCreator();
    }

    @Bean
    FactoryBean<IPersonApi> userApi(ProxyCreator proxyCreator) {
        return new FactoryBean<IPersonApi>() {

            @Override
            public Class<?> getObjectType() {
                return IPersonApi.class;
            }

            /**
             * 返回代理对象
             */
            @Override
            public IPersonApi getObject() throws Exception {
                return (IPersonApi) proxyCreator
                        .createProxy(this.getObjectType());
            }
        };
    }

}
